from rest_framework import serializers

from user_model.models import ComplainModel


class RegisterSerializer(serializers.Serializer):
    name = serializers.CharField(max_length=20, min_length=2, required=True, error_messages={
        'max_length': '名字最长20个字符',
        'min_length': '名字最短2个字符',
    })
    password = serializers.CharField(max_length=18, min_length=6, required=True, error_messages={
        'max_length': '名字最长18个字符',
        'min_length': '名字最短6个字符',
    })
    ID_card = serializers.CharField(max_length=18, min_length=18, required=True, error_messages={
        'max_length': '身份证必须18位',
        'min_length': '身份证必须18位',
    })
    address = serializers.CharField(min_length=3, required=True, error_messages={
        'min_length': '住址不能少于3位字符',
    })
    phone = serializers.CharField(max_length=11, min_length=11, required=True, error_messages={
        'max_length': '手机号必须为11位',
        'min_length': '手机号必须为11位',
    })


class LoginSerializer(serializers.Serializer):
    login_name = serializers.CharField(min_length=2, required=True, error_messages={
        'min_length': '名字最短2个字符',
    })
    password = serializers.CharField(max_length=18, min_length=6, required=True, error_messages={
        'max_length': '名字最长18个字符',
        'min_length': '名字最短6个字符',
    })


class ModificationSerializer(serializers.Serializer):
    address = serializers.CharField(min_length=3, required=True, error_messages={
        'min_length': '住址不能少于3位字符',
    })


class ComplaintSerializer(serializers.Serializer):
    ID_card = serializers.CharField(max_length=18, min_length=18, required=True, error_messages={
        'max_length': '身份证必须18位',
        'min_length': '身份证必须18位',
    })
    title = serializers.CharField(max_length=128, min_length=6, required=True, error_messages={
        'max_length': '标题最多128个字符',
        'min_length': '标题最少6个字符',
    })


class ArticleSerializer(serializers.Serializer):
    class Meta:
        model = ComplainModel
        fields = '__all__'

# class ArticleSerializer(serializers.ModelSerializer):
#     class Meta:
#         model = ComplainModel
#         fields = '__all__'
#         read_only_fields = ('id', 'author', 'create_date')